// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router/index.js'
import Vuex from 'vuex'
// 引入elementUI
import ElementUI from 'element-ui';
import store from './store'
import 'element-ui/lib/theme-chalk/index.css';

import './assets/global.css';

import axios from 'axios';
Vue.prototype.$axios = axios
axios.defaults.timeout = 8000;
axios.defaults.baseURL = 'http://124.71.160.140:9090/'

// axios.defaults.baseURL = 'http://121.40.54.171:9090/'



Vue.config.productionTip = false

Vue.use(Vuex)
Vue.use(ElementUI);

// http request 拦截器
axios.interceptors.request.use(
  config => {
    if (localStorage.token) { //判断token是否存在
      config.headers.Authorization = localStorage.token  //将token设置成请求头
    }
    return config;
  },
  err => {
    return Promise.reject(err);
  }
);
// http response 拦截器
axios.interceptors.response.use(
  response => {
    // token过期
    // if (response.data.code === '401') {
    //   router.replace('/login');
    //   window.alert("登入超时,请重新登入");
    //   // console.log("token过期");
    // }
    return response;
  },
  error => {
    return Promise.reject(error);
  }
);

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
  store,
})
